using System;

namespace AgileCode.Practice.Step04
{
    public class Demo
    {
        public static void Run()
        {
            Copier.reader = new PaperTapeHandler();
            Copier.writer = new PaperTapeHandler();
            Copier.Copy();
        }
    }

    public interface IReader
    {
        char Read();
    }

    public interface IWriter
    {
        void Write(char c);
    }

    public static class Copier
    {
        // The agile way - first change request revisited

        public static IReader reader;
        public static IWriter writer;

        public static void Copy()
        {
            if (reader == null || writer == null) return;

            char c;
            while (Char.ToLower(c = reader.Read()) != 'x')
                writer.Write(c);
        }
    }

    public class KeyboardReader : IReader
    {
        public char Read()
        {
            return Keyboard.Read();
        }
    }

    public class PrinterWriter : IWriter
    {
        public void Write(char c)
        {
            Printer.Write(c);
        }
    }

    public class PaperTapeHandler : IReader, IWriter
    {
        public char Read()
        {
            return PaperTape.Read();
        }

        public void Write(char c)
        {
            PaperTape.Punch(c);
        }
    }
}